package com.wad.manager.controller;

import com.github.pagehelper.PageInfo;
import com.wad.entity.product.ProductSpec;
import com.wad.manager.service.ProductSpecService;
import com.wad.vo.common.Result;
import com.wad.vo.common.ResultCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author wad
 * @date 2023/12/08 16:37
 * @project e-commerce
 **/

@RestController
@RequestMapping("/admin/product/productSpec")
public class ProductSpecController {

    @Resource
    private ProductSpecService productSpecService;


    //分页查询
    @GetMapping("/findByPage/{page}/{limit}")
    public Result findByPage(@PathVariable("page") Integer page,@PathVariable("limit") Integer limit){
        PageInfo<ProductSpec> pageInfo=productSpecService.findByPage(page,limit);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    //新增
    @PostMapping("/save")
    public Result save(@RequestBody ProductSpec productSpec){
        productSpecService.save(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    //修改
    @PutMapping("/update")
    public Result update(@RequestBody ProductSpec productSpec){
        productSpecService.update(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    //删除
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        productSpecService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
